package com.lepu.app.fun.bbs.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.lepu.app.fun.my.bean.BeanMyCollect;

@SuppressWarnings("serial")
public class BeanBbs  extends BeanMyCollect implements Serializable{

    public String bbsID;
    public String bbsAvatar;
    public String bbsUserId;
    public String bbsUserName;
    public String bbsTime;  //创建时间
    public String bbsReplyTime; //回复时间
    public String bbsUpdateTime; //更新时间
    public String bbsCommentCount;  //回复数量
    public String bbsLookCount;  //浏览次数
    public String bbsLikeCount;  //点赞数量
    
    public String bbsTitle;
    public String bbsContent;
    
    public int bbsIsLike;  //是否点赞
    public int bbsIsTop;   //是否置顶
    public int bbsIsGood;  //是否精华 0-否，1-是
    
    public List<String> bbsImageUrl; // 图片集合
    
    //wuxd new add
    public String CheckStatus;//	审核状态	0-拒绝  1-通过
    public String ForumName;//板块名称
    public String ForumID;//板块id   1-支架人生 2-支架术后
  
    public static ArrayList<BeanBbs> parseJsonData(String dataString) {
    	ArrayList<BeanBbs> topicList = new ArrayList<BeanBbs>();
        try {
            JSONObject jsonObject = new JSONObject(dataString);
            JSONObject obj1 = (JSONObject) jsonObject.get("Result");
            JSONArray dataArray = obj1.getJSONArray("ListInfo");

            for(int i=0; i<dataArray.length(); i++){
				JSONObject focusJson = (JSONObject) dataArray.get(i);
				BeanBbs motherTopic = new BeanBbs();
				motherTopic.bbsID = focusJson.optString("ThreadID");
				motherTopic.bbsAvatar = focusJson.optString("Avatar");
				motherTopic.bbsUserId = focusJson.optString("AuthorID");
				motherTopic.bbsUserName = focusJson.optString("NickName");
				motherTopic.bbsTime = focusJson.optString("RecordCreateTime"); //发表时间
				motherTopic.bbsReplyTime = focusJson.optString("RecordReplyTime"); //最后回复时间
				motherTopic.bbsUpdateTime = focusJson.optString("RecordUpdateTime"); //最后编辑时间
				motherTopic.bbsCommentCount = focusJson.optString("ReplyCount");
				motherTopic.bbsLookCount = focusJson.optString("ViewCount");
				motherTopic.bbsLikeCount = focusJson.optString("FavourCount");
				motherTopic.bbsTitle = focusJson.optString("Subject");
				motherTopic.bbsContent = focusJson.optString("Abstract");//
				motherTopic.bbsIsTop = focusJson.optInt("IsTop");
				motherTopic.bbsIsLike = focusJson.optInt("HasFavour");
				motherTopic.bbsIsGood = focusJson.optInt("IsGood");
				//motherTopic.bbsImageUrl = parseJsonImage(focusJson.optString("PicUrls"));
				motherTopic.bbsImageUrl = (List<String>) Arrays.asList(focusJson.optString("PicUrls").split("\\|"));
				
				//wuxd new add
				motherTopic.CheckStatus = focusJson.optString("CheckStatus");
				motherTopic.ForumName = focusJson.optString("ForumName");
				motherTopic.ForumID = focusJson.optString("ForumID");//
				
				//wuxd new add collect list
				motherTopic.Abstract = focusJson.optString("Abstract");
				motherTopic.ApplicationID = focusJson.optString("ApplicationID");
				motherTopic.CollectionID = focusJson.optString("CollectionID");
				motherTopic.RecordCreateTime = focusJson.optString("RecordCreateTime");
				motherTopic.Tag = focusJson.optString("Tag");
				motherTopic.TargetID = focusJson.optString("TargetID");
				motherTopic.TargetType = focusJson.optString("TargetType");
				motherTopic.Title = focusJson.optString("Title");
				motherTopic.UserID = focusJson.optString("UserID");
				
				topicList.add(motherTopic);
			}
        } catch (JSONException e) {
            e.printStackTrace();
        }
        
        return topicList;
    }

    //刷新时间
    public static String parseJsonDate(String dataString) {
    	String date = "";
        try {
            JSONObject jsonObject = new JSONObject(dataString);
            JSONObject obj1 = (JSONObject) jsonObject.get("Result");
            JSONObject objDetail = obj1.getJSONObject("DetailInfo");
            date = objDetail.getString("RefreshTime");

        } catch (JSONException e) {
            e.printStackTrace();
        }
        
        return date;
    }
    
    //解析图片
    public static List<String> parseJsonImage(String imageString){
    	List<String> imageList = new ArrayList<String>();
    	String [] imageArray = imageString.split("\\|");
    	for(int i=0; i<imageArray.length; i++){
    		imageList.add(imageArray[i]);
    	}
		return imageList;
    }
    
    public static ArrayList<BeanBbs> getTestDataType(){
    	ArrayList<BeanBbs>  list = new ArrayList<BeanBbs>();
    	
    	for(int i=0; i<10; i++){
    		BeanBbs bean = new BeanBbs();
    		bean.bbsUserName = "乐普医疗";
        	bean.bbsReplyTime = "10分钟前";
        	bean.bbsCommentCount = "99";
        	bean.bbsLookCount = "999";
        	bean.bbsTitle = "乐普医疗的新产品";
        	bean.bbsContent = "乐普医疗的新产品有哪些优点呢,欲知后事如何，请听下回分解，啦啦啦啦啦啦啦啦";
        	bean.bbsIsGood = 1;
        	
        	List<String> urlList = new ArrayList<String>();
			for (int k = 0; k < 3; k++) {
				urlList.add("www");
			}
			bean.bbsImageUrl = urlList;
			list.add(bean);
    	}
    	
        return list;
    }
    
}
